/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-07-08 17:55:54
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2024-07-12 10:49:31
 * @FilePath: \dwys_web\assets\script\ui\login\Login.ts
 * @Description: 
 */
import { _decorator, Component, Node } from 'cc';
import { oops } from '../../../../extensions/oops-plugin-framework/assets/core/Oops';
import { GameEvent } from '../../common/event/GameEvent';
import { CCComp } from '../../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
import { PhoenixClient } from '../../phoenix/PhoenixClient';
import { EditBox } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Login')
export class Login extends CCComp {

    @property(EditBox)
    editBoxAccount: EditBox = null!;

    @property(EditBox)
    editBoxPasswd: EditBox = null!;

    reset(): void {
        
    }

    start() {
        oops.message.on(GameEvent.LoginAccountServerSuccess, this.onHandler, this)
        oops.message.on(GameEvent.LoginAccountServerFail, this.onHandler, this)
    }

    protected onDestroy(): void {
        oops.message.off(GameEvent.LoginAccountServerSuccess, this.onHandler, this)
        oops.message.off(GameEvent.LoginAccountServerFail, this.onHandler, this)
    }

    private onHandler(event: string, ...args: any) {
        switch (event) {
            case GameEvent.LoginAccountServerSuccess:
                this.callBackLoginSuccess(args);
                break;
            case GameEvent.LoginAccountServerFail:
                this.callBackLoginFail(args);
                break;
            default:
                break;
        }
    }
    
    callBackLoginSuccess(recode:any){
        console.log(recode);
        oops.message.dispatchEvent(GameEvent.LoginAccountServerComplete);
    }

    callBackLoginFail(recode:any){
        console.log(recode);
    }

    onClickLogin() {
        oops.message.dispatchEvent(GameEvent.GameStartLogin, this.editBoxAccount.string, this.editBoxPasswd.string);
    }
}


